package service;

import java.sql.Connection;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Constan {
	private static Pattern pattern;
	private static Matcher matcher;
	public final static int SER_STATUS_SUCSESS = 1;
	public final static int SER_STATUS_EROOR = 0;
	public final static String SER_STATUS_TRUE="YES";
	public final static String SER_STATUS_FALSE="NO";
	public final static String LOCATION_THNC="THNC";
	public final static String LOCATION_HN="HaNoi";
	public final static String LOCATION_HCM="HCM";
	public static final String EMAIL_PATTERN = 
			"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
					+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
	public static final String DISPLAY_EMP="|id\t\t|name\t\t\t|username\t\t|email";
	public final static String DISPLAY_PJ="|id\t\t|nameProject\t\t|startDate\t\t|endDate";
	public final static String DISPLAY_TS="|Id\t\t|Employeeid\t|Projectid\t|Date\t\t\t|Duration\t\t|Description\t\t|Activity\t\t|Overtime\t|Location";
	
	private Connection conn = null;
	
	public static boolean isValidDate(String date) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
		try {
			dateFormat.setLenient(false);
			dateFormat.parse(date);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	public static boolean isValidEmailAddress(String email) {
		String ePattern = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$";
		java.util.regex.Pattern p = java.util.regex.Pattern.compile(ePattern);
		java.util.regex.Matcher m = p.matcher(email);
		return m.matches();
	}
	public static boolean checkDate(String startDate,String endDate){
		Calendar sd=Calendar.getInstance();
		Calendar ed=Calendar.getInstance();
		SimpleDateFormat sf=new SimpleDateFormat("dd/mm/yyyy");
		try {
			sd.setTime(sf.parse(startDate));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		try {
			ed.setTime(sf.parse(endDate));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		if(sd.before(ed))return true;
		return false;
	}
	
	
	public static Connection dataConnection() {
		Connection conn = null;
		String userName = "root";
		String password = "123456";
		String url = "jdbc:mysql://localhost/test?"
				+ "user=root&password=123456";
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			System.out.println("khong load duoc thu vien");
			e.printStackTrace();
		}
		try {
			conn = java.sql.DriverManager
					.getConnection(url, userName, password);
			return conn;
		} catch (SQLException e) {
			System.out.println("Khong ket noi duoc db");
			e.printStackTrace();

		}
		return conn;
	}
	
	 
}
